*Climate Change Literacy and Migration Potential: Micro-Level Evidence from Africa
*Published in Climatic Change

**********
*RECODING*
**********
set seed 1516
global red "200 0 0"
global blue "68 119 170"
global yellow "204 187 68"
global green "34 136 51"
global orange "233 118 0"
global magenta "150 79 142"

*Dependent variable migration aspirations
g mig_binary = .
	replace mig_binary = 0 if migconsider == 0
	replace mig_binary = 1 if migconsider >= 1 & migconsider != .

*Independent variable climate change literacy
gen climlit3=0
recode climlit3 (0=1) if Q73A==1 & (Q75==4 | Q75==5 | Q73B==1)

*Covariates
g female = .
	replace female = 0 if male == 1
	replace female = 1 if male == 0

g prof = .
	replace prof = 0 if occupation == 0 | occupation == 2 
	replace prof = 1 if occupation == 3 
	replace prof = 2 if occupation >= 4 & occupation <= 8
	replace prof = 3 if occupation >= 9 & occupation <= 12
	replace prof = 4 if occupation == 1
la def prof 0 "   Not working" 1 "Farmer" 2 "Unskilled" 3 "Specialist" 4 "Student"
la val prof prof
	
la def education 0 "No education" 1 "Primary" 2 "Secondary" 3 "Post-secondary", modify
la val education education

foreach i in Q12E Q12D Q12C Q12B Q12A {
	replace `i' = . if `i' >= 8
	}
egen news = rowmean(Q12D Q12C Q12B Q12A Q12E)
	replace news = round(news,1)

g wsdi = wsdi_s14 * 100

**********
*ANALYSES*
**********
*Figure 1: Trends in Warm Spell Durations and Interview Locations
*Access to the geo-coordinates of the Afrobarometer data that is necessary to produce this figure is by application only. More details on the procedure can be found at https://afrobarometer.org/data/geocoded-data.


*Figure 2: Effect of Climate Change Variables on Migration Intentions for Climate Literates and Illiterates
su $indicators
su mig_binary annual_trend_1979_2016 annual_trend_2009_2016 wsdi_era5_09_17minus wsdi_era5_10y wsdi_era5 hwm_ehf_10y spei_12_mth climlit3 urban education prof news female age

rename wsdi_era5_09_17minus79_08 wsdi_era5_09_17minus

global indicators annual_trend_1979_2016 annual_trend_2009_2016 ///
				wsdi_era5_09_17minus wsdi_era5_10y wsdi_era5 ///
				hwm_ehf_10y spei_12_mth  
				
foreach i in $indicators {
	su `i'
	replace `i' = (`i' - r(min)) / (r(max) - r(min))
	reg mig_binary c.`i'##climlit3 female age i.country i.climate_zone_KG, robust cluster(mmid)
	eststo lit_`i': margins, dydx(`i') at(climlit3==1) post
	reg mig_binary c.`i'##climlit3 female age i.country i.climate_zone_KG, robust cluster(mmid)
	eststo nol_`i': margins, dydx(`i') at(climlit3==0) post	
	reg mig_binary c.`i'##climlit3 female age i.country i.climate_zone_KG, robust cluster(mmid)
	eststo `i': margins, dydx(`i') at(climlit3==(0 1)) post
	test _b[`i':1bn._at]==_b[`i':2._at]
		global p_`i' : di %4.3f `r(p)'
}				

	
		coefplot (lit_annual_trend_1979_2016, msym(Oh) mc("$green") ciopts(color("$green%75")) offset(0.15)) (nol_annual_trend_1979_2016, msym(Th) mc("$orange") ciopts(color("$orange%75")) offset(-0.15)) ///
		(lit_annual_trend_2009_2016, msym(Oh) mc("$green") ciopts(color("$green%75")) offset(0.15)) (nol_annual_trend_2009_2016, msym(Th) mc("$orange") ciopts(color("$orange%75")) offset(-0.15)) ///
		(lit_wsdi_era5_09_17minus, msym(Oh) mc("$green") ciopts(color("$green%75")) offset(0.15)) (nol_wsdi_era5_09_17minus, msym(Th) mc("$orange") ciopts(color("$orange%75")) offset(-0.15)) ///
		(lit_wsdi_era5_10y, msym(Oh) mc("$green") ciopts(color("$green%75")) offset(0.15)) (nol_wsdi_era5_10y, msym(Th) mc("$orange") ciopts(color("$orange%75")) offset(-0.15)) ///
		(lit_wsdi_era5, msym(Oh) mc("$green") ciopts(color("$green%75")) offset(0.15)) (nol_wsdi_era5, msym(Th) mc("$orange") ciopts(color("$orange%75")) offset(-0.15)) ///
		(lit_hwm_ehf_10y, msym(Oh) mc("$green") ciopts(color("$green%75")) offset(0.15)) (nol_hwm_ehf_10y, msym(Th) mc("$orange") ciopts(color("$orange%75")) offset(-0.15)) ///
		(lit_spei_12_mth, msym(Oh) mc("$green") ciopts(color("$green%75")) offset(0.15)) (nol_spei_12_mth, msym(Th) mc("$orange") ciopts(color("$orange%75")) offset(-0.15)) ///
			, legend(order(2 "Knowledge about climate change" 4 "No climate literacy") rows(2) ring(1) pos(6) size(small)) ///
			xline(0, lc(red))  xlabel(-0.4(0.1)0.4, labsize(small)) ylabel(, labsize(small)) ///
			title ("Effect of temperature increases" "on the %-probability to state emigration intentions" "(standardized indices, ERA5-level)", size(small)) ///
			coeflab( ///
				annual_trend_1979_2016 =	`" "{bf:WSDI annual trend, 1979-2016}" "(p-diff=$p_annual_trend_1979_2016)" "'   ///
				annual_trend_2009_2016 =	`" "{bf:WSDI annual trend, 2009-2016}" "(p-diff=$p_annual_trend_2009_2016)" "' ///
				wsdi_era5_09_17minus = 		`" "{bf:WSDI change [2009-16]-[1979-08]}" "(p-diff=$p_wsdi_era5_09_17minus)" "' ///
				wsdi_era5_10y = 			`" "{bf:WSDI 10-year average}" "(p-diff=$p_wsdi_era5_10y)" "' ///
				wsdi_era5 = 				`" "{bf:WSDI 3-year average}" "(p-diff=$p_wsdi_era5" "' ///
				hwm_ehf_10y = 				`" "{it:HWM 10-year average}" "(p-diff=$p_hwm_ehf_10y" "' ///		
				spei_12_mth = 				`" "{it:SPEI 3-year average}" "(p-diff=$p_spei_12_mth" "')		
		graph export "main_figure.pdf", replace

				


*Figure 3: Correlates of Climate Change Literacy
foreach i in  urban education prof news {
g outcome = `i'
reg climlit3 i.outcome i.country i.climate_zone_KG, robust cluster(mmid)
margins outcome, saving(`i', replace)
drop outcome 
}

combomarginsplot urban education prof news, ///
	file1opts(lw(medium) lp(shortdash) lcolor(gs7%75) msym(oh) mc(gs7%75)) 	fileci1opts(lw(medium) color(gs7%75) recast(cap)) ///
	file2opts(lw(medium) lp(solid) lcolor(sienna%75) msym(oh) mc(sienna%75)) 	fileci2opts(lw(medium) color(sienna%75) recast(cap)) ///
	file3opts(lw(medium) lp(dash_dot) lcolor(midblue%75) msym(oh) mc(midblue%75)) 		fileci3opts(lw(medium) color(midblue%75) recast(cap)) ///
	file4opts(lw(medium) lp(longdash) lcolor(teal%75) msym(oh) mc(teal%75)) 			fileci4opts(lw(medium) color(teal%75) recast(cap)) ///
legend(size(vsmall) ring(1) pos(6) rows(4) order(8 "{bf:News consumption} (never|<1x p.m.|few p.m.|few p.w.|daily)" ///
			7 "{bf:Profession} (none|farmer|unskilled|specialis|student)" ///
			6 "{bf:Education} (none|primary|secondary|post-sec)" ///
			5 "{bf:Location} (rural|urban)")) ///
			xtitle("") ytitle("Predicted climate literacy", size(small)) title("") ylabel(0.2(0.1)0.7, labsize(vsmall) nogrid) xlabel(, labsize(vsmall) nogrid) ///
			xsize(10) ysize(10)
graph export "predict_climlit_1short.pdf", replace

foreach i in  urban education prof news {
				erase `i'.dta
			}
			
**********
*APPENDIX*
**********
*Table S3: Effect of Climate Change Variables on Migration Intentions for Climate Literates and Illiterates
foreach i in annual_trend_1979_2016 annual_trend_2009_2016 wsdi_era5_09_17minus wsdi_era5_10y wsdi_era5 hwm_ehf_10y spei_12_mth {
reg mig_binary c.`i'##climlit3 female age i.country i.climate_zone_KG, robust cluster(mmid)
}

*Table S4: Effect of Climate Change Variables on Migration Intentions for Climate Literates and Illiterates, Ordinal Logistic Regression
foreach i in annual_trend_1979_2016 annual_trend_2009_2016 wsdi_era5_09_17minus wsdi_era5_10y wsdi_era5 hwm_ehf_10y spei_12_mth {
ologit mig_binary c.`i'##climlit3 female age i.education i.country i.climate_zone_KG, robust cluster(mmid)
}

*Table S5: Effect of Climate Change Variables on Migration Intentions for Climate Literates and Illiterates, Controlling for Education
foreach i in annual_trend_1979_2016 annual_trend_2009_2016 wsdi_era5_09_17minus wsdi_era5_10y wsdi_era5 hwm_ehf_10y spei_12_mth {
reg mig_binary c.`i'##climlit3 female age i.education i.country i.climate_zone_KG, robust cluster(mmid)
}

*Table S6: Correlates of Climate Change Literacy
foreach i in urban education prof news {
reg climlit3 i.`i' i.country i.climate_zone_KG, robust cluster(mmid)
}

*Figure S1: Correlation of Climate Change Literacy and local WSDI trend
bys annual_trend_1979_2016: egen av_climlit3 = mean(climlit3)
bys annual_trend_1979_2016: g locid = _n

twoway (scatter av_climlit3 annual_trend_1979_2016 if locid == 1, msym(o) mc("$green%75")) ///
		(lfit av_climlit3 annual_trend_1979_2016 if locid == 1, lp(solid) lc("$orange") ///
		legend(off) ylabel(, nogrid) ytitle("Climate literacy among the local population"))
graph export "corr_climlit_wsdi.pdf", replace

drop locid av_climlit3